from __future__ import absolute_import
from .celery import app as celery_app
import pymysql

pymysql.install_as_MySQLdb()

__all__ = ['celery_app']

# 单例实例
_scheduler_instance = None
_task_manager_instance = None
_YourAppConfig_instance = None

# 懒加载获取scheduler实例
def scheduler():
    from processutil.scheduler import TaskScheduler
    return TaskScheduler()

# 懒加载获取taskManager实例
def taskManager():
    global _task_manager_instance
    if _task_manager_instance is None:
        from processutil.Process import TaskManager
        _task_manager_instance = TaskManager()
    return _task_manager_instance


# yourapp/apps.py

# from django.apps import AppConfig

# class YourAppConfig(AppConfig):
#     name = 'link'

#     def ready(self):
#         global _YourAppConfig_instance
#         if _YourAppConfig_instance is None:
#             from link.api import my_hourly_task
#             my_hourly_task.delay()  # 启动时触发一次

# YourAppConfig().ready()